home *** CD-ROM | disk | FTP | other *** search
- /*
- SimpleInMovies
-
- Sample programs demonstrating how to open and display
- QuickTime™ Movies.
-
- SimpleInLOOP.c file contains the code for the routines
- having to do with checking for the existance of the LOOP user data atom.
- This is the mechanism that can allow applications opening movies to set the
- loop state the movie was saved with.
- Applications that allow the user to change the state of a movie should also save
- the loop state if it changed since the movie was opened.
-
- Guillermo A. Ortiz
- Macintosh Developer Technical Support
-
- 10/08/92 -- New with code to check for loop atom in the user data and also to save the
- proper user data if the looping state changed.
-
- */
-
- #include <SimpleInMovie.h>
- short GetFileLoopState(DocRecHandle DocHandle);
- void SetLoopState(DocRecHandle wHndl);
- short GetCurrentLoopState(DocRecHandle wHndl);
- void UpdateLoopStateInfo(DocRecHandle wHndl);
- void FixWindowPosition(WindowPtr w,DocRecHandle wHndl);
- Boolean WPositionChanged(WindowPtr w,DocRecHandle DocHandle);
- void UpdateWindowPos(void);
-
- short GetFileLoopState(DocRecHandle DocHandle)
- {
- UserData uData;
- short dataCount;
- Handle data;
- OSErr error;
-
- if ( !(data = NewHandle(4)) ) /* first try to make room for the result but if */
- return (noLoop); /* NewHandle fails return noLoop as the default */
-
- if ( uData = GetMovieUserData((*DocHandle)->wMovie) ) { /* get user data */
- if ( dataCount = CountUserDataType(uData, 'LOOP') ) { /* if any count loop atoms */
- error = GetUserData(uData, data, 'LOOP', 1); /* and get the first loop atom */
-
- if (*((short *)*data))
- return (loopIsPalindrome);
- else
- return (loopNormal);
- }
- }
- DisposeHandle(data);
-
- return noLoop; /* default */
- }
-
-
-
- /* the movie came looping and here the correct state is set for it */
- void SetLoopState(DocRecHandle wHndl)
- {
- switch ((*wHndl) -> loopState) {
- case loopNormal:
- MCDoAction((*wHndl)->wPlayer, mcActionSetLooping, (void *)loopNormal);
- break;
- case loopIsPalindrome: /* palindrome requires looping to be enabled. */
- MCDoAction((*wHndl)->wPlayer, mcActionSetLooping, (void *)loopNormal);
- MCDoAction((*wHndl)->wPlayer, mcActionSetLoopIsPalindrome, (void *)1);
- break;
- }
- }
-
- short GetCurrentLoopState(DocRecHandle wHndl)
- {
- long mcInfo;
- short result = 0;
-
- if ( MCGetControllerInfo((*wHndl)->wPlayer, &mcInfo) )
- DebugStr("\pCould not get controller info");
-
- if ( (mcInfo & mcInfoIsLooping) ) {
- result++;
- if ( (mcInfo & mcInfoIsInPalindrome) )
- result++;
- }
- return result;
- }
-
- void UpdateLoopStateInfo(DocRecHandle wHndl)
- {
- short loopState, dataCount;
- Handle loopy;
- UserData uData;
-
- loopState = GetCurrentLoopState(wHndl);
-
- if (loopState != (*wHndl)->loopState) { /* OK is different than the last time it was saved */
- if (uData = GetMovieUserData( (*wHndl)->wMovie ) ) { /* let start by removing whatever */
- dataCount = CountUserDataType(uData, 'LOOP'); /* is there. */
- while (dataCount--)
- RemoveUserData(uData, 'LOOP',1);
- }
- if (loopy = NewHandle(2) ) { /* get a handle */
- if (loopState) { /* and add the atom if necessary */
- switch (loopState) {
- case loopNormal:
- *((short *) *loopy) = 0;
- break;
- case loopIsPalindrome:
- *((short *) *loopy) = 0x0100;
- break;
- }
- AddUserData(uData, loopy, 'LOOP');
- }
- }
- }
- (*wHndl)->loopState = loopState;
- DisposeHandle(loopy);
- }
-
- /**********************************************************************************************//**********************************************************************************************/
- /**********************************************************************************************//**********************************************************************************************/
- /**********************************************************************************************//**********************************************************************************************/
- /* as a freebie we'll add here the code needed to get/set the WLOC user data atom.
- This atom is used to keep the last position of the file so that it opens in the
- same place.
- */
-
- void FixWindowPosition(WindowPtr w,DocRecHandle DocHandle)
- {
- UserData uData;
- short dataCount;
- Point **data;
- OSErr error;
-
- if ( !(data = (Point **)NewHandle(4)) ) /* first try to make room for the result but if */
- return; /* NewHandle fails return */
-
- if ( uData = GetMovieUserData((*DocHandle)->wMovie) ) { /* get user data */
- if ( dataCount = CountUserDataType(uData, 'WLOC') ) { /* if any count loop atoms */
- if ( !(error = GetUserData(uData, (Handle)data, 'WLOC', 1) )) /* and get the first loop atom */
- MoveWindow(w, (*data)->h, (*data)->v, false);
- }
- }
- DisposeHandle((Handle)data);
- }
-
- Boolean WPositionChanged(WindowPtr w,DocRecHandle DocHandle)
- {
- UserData uData;
- short dataCount;
- Point **data;
- OSErr error;
- Boolean result = true;
-
- if ( !(data = (Point **)NewHandle(4)) ) /* first try to make room for the result but if */
- return false; /* NewHandle fails return who knows what the old position was */
-
- if ( uData = GetMovieUserData((*DocHandle)->wMovie) ) { /* get user data */
- if ( dataCount = CountUserDataType(uData, 'WLOC') ) { /* if any count loop atoms */
- if ( ! ( error = GetUserData(uData, (Handle)data, 'WLOC', 1) ) ) /* and get the first loop atom */
- if( (w->portRect.left == (*data)->h) && (w->portRect.top ==(*data)->v) )
- result = false;
- }
- }
- DisposeHandle((Handle)data);
- return result;
- }
-
- void UpdateWindowPos(void)
- {
- short dataCount;
- Point **wCorner;
- UserData uData;
-
- WindowPtr window;
- DocRecHandle wHndl;
- GrafPtr oldPort;
-
- GetPort(&oldPort);
-
- if (window = FrontWindow()) { /* don't bother if no movies to play */
- SetPort(window);
- wHndl = (DocRecHandle)GetWRefCon(window);
- if (uData = GetMovieUserData( (*wHndl)->wMovie ) ) { /* let start by removing whatever */
- dataCount = CountUserDataType(uData, 'WLOC'); /* is there. */
- while (dataCount--)
- RemoveUserData(uData, 'WLOC',1);
- }
- if (wCorner = (Point **)NewHandle(4) ) { /* get a handle */
- (*wCorner)->h = window->portRect.left;
- (*wCorner)->v = window->portRect.top;
- LocalToGlobal((*wCorner));
- AddUserData(uData, (Handle)wCorner, 'WLOC');
- DisposeHandle((Handle)wCorner);
- }
- }
- SetPort(oldPort);
- }
-
-